package webbandidong.model;

import java.io.Serializable;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "tbl_order_details")
@AssociationOverrides({
    @AssociationOverride(name = "orderDetailsId.mobile",
        joinColumns = @JoinColumn(name = "mobile_id")),
    @AssociationOverride(name = "orderDetailsId.mobileOrder",
        joinColumns = @JoinColumn(name = "order_id"))})
public class OrderDetails implements Serializable {

    private OrderDetailsId orderDetailsId = new OrderDetailsId();

    private int amount;

    public OrderDetails() {
        
    }

    public OrderDetails(OrderDetailsId orderDetailsId, int amount) {
        this.orderDetailsId = orderDetailsId;
        this.amount = amount;
    }

    @EmbeddedId
    public OrderDetailsId getOrderDetailsId() {
        return orderDetailsId;
    }

    public void setOrderDetailsId(OrderDetailsId orderDetailsId) {
        this.orderDetailsId = orderDetailsId;
    }

    @Transient
    public Mobile getMobile() {
        return getOrderDetailsId().getMobile();
    }

    public void setMobile(Mobile mobile) {
        getOrderDetailsId().setMobile(mobile);
    }

    @Transient
    public Order getOrder() {
        return getOrderDetailsId().getMobileOrder();
    }

    public void setOrder(Order order) {
        getOrderDetailsId().setMobileOrder(order);
    }

    @Column(name = "amount", nullable = false)
    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || obj.getClass() != OrderDetails.class) {
            return false;
        }
        OrderDetails orderDetails = (OrderDetails)obj;
        if (!this.orderDetailsId.equals(orderDetails.orderDetailsId) ||
                this.amount != orderDetails.amount) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + (this.orderDetailsId != null ? this.orderDetailsId.hashCode() : 0);
        hash = 31 * hash + this.amount;
        return hash;
    }
}
